PostgreSQL date_trunc() 和timestamp

timestamp

01.SELECT now()::timestamp + '1 year';
02.SELECT now()::timestamp + '1 month';
03.SELECT now()::timestamp + '1 day';
04.SELECT now()::timestamp + '1 hour';
05.SELECT now()::timestamp + '1 min';
06.SELECT now()::timestamp + '1 sec';
07.select now()::timestamp + '1 year 1 month 1 day 1 hour 1 min 1 sec';
08.SELECT now()::timestamp + (col || ' day')::interval FROM table

date_trunc()

select date_trunc('month',now()) +interval '12 h';		
//每月1号 12点		
select date_trunc('month',now()) + interval '15 d 9 h 30 min';		
//每月15号9点半		
select date_trunc('day',now()) + interval '9 h';		
//每天9点		
select date_trunc('day',now()) + interval '7 d';		
//每周的今天		
select date_trunc('weak',now())  + interval '1d 1minute';		
//每周的周二第一分钟		
select date_trunc('h',now()) + interval '30 minute';		
//每小时		
select date_trunc('minute',now()) + interval '30 second';		
//每分钟		
select date_trunc('minute',now()) + interval '30 minute 30 second';		
//每30分钟 			
select date_trunc('quarter',now()) + interval '15 d 15 h 15 minute 30 second';		
//本季度的第15天,15小时 15分 30秒		
select date_trunc('quarter',now() ) - interval '1 h';		
//每个季度最后一天的晚上11点		
select date_trunc('quarter',now() + interval '3 month') - interval '1 h';		
//每个季度的最后一天的晚上的11点(从下个季度开始算起).	
posted @ 2019-03-26 12:57  最爱江南小冷  阅读(7823)  评论(0编辑  收藏  举报